BIG-IP APM Best Practices Anthony Graber – Solutions Engineer, DISA

©2024 F52

Agenda

BIG-IP APM Overview

Smart Cards and APM

Configuration Walkthrough and Recommended Practices

©2024 F53

BIG-IP APM Overview

©2024 F54

Full Proxy Architecture

Network

Session

Application

Web application

Physical

Client / Server

L4 Firewall: Full stateful policy enforcement and TCP DDoS mitigation

SSL inspection and SSL DDoS mitigation

HTTP proxy, HTTP DDoS and application security

Application health monitoring and performance anomaly detection

Network

Session

Application

Web application

Physical

Client / Server

©2024 F55

F5’s Remote/Application Access Solutions AUTHENTICATION, AUTHORIZATION, REMOTE ACCESS AND SSO TO ALL APPLICATIONS WITH CENTRALIZED ACCESS POLICY ENFORCEMENT USING ACCESS POLICY MANAGER (APM)

Remote Access and Application Access

Identity Federation/SSO

Secure Web Gateway

Access Management

Mobile Apps

Apps/API Enterprise Apps

Cloud, SaaS,

and Partner Apps

Websites/Web Applications

Virtual Edition Chassis Appliance

Enterprise Mobility Gateway

Virtual Apps VDI

©2024 F56

PKI / OCSP / CRL

Kerberos

SAML

AD / LDAP

RADIUS / TACACS

HTTP / NTLM / Basic

Form

Kerberos

SAML/WS-FED

HTTP / NTLM / Basic

Form BIG-IP APM is a

FULL PROXY Architecture

for

Authentication Protocols PKI

Full Proxy Architecture for Authentication

©2024 F57

F5 Access Policy Manager (APM)

7

Client

Certificates

Password

MFA / Token

Federation

Adaptive Auth

Certificates

Dynamic Forms

Kerberos Delegation

Simple Assertion

SAML Pass-through

Services

Private/Public Cloud

SSO Selection

Endpoint Validation

Step-Up Auth

Fraud Protection

Transform one type of authentication into another so an app may understand and use it without installing additional agents

Allow flexible selection of SSO technique appropriate to the application

Allow for centralized session control of all applications

©2024 F58

Access Policy Design

©2024 F59

Access Policy Design

©2024 F510

Access Policy Design

©2024 F511

Access Policy Design

©2024 F512

12

General protocol flow Client Side Server Side

©2024 F513

13

General protocol flow Client Side Server Side

Initial request “/foo”

©2024 F514

14

General protocol flow Client Side Server Side

Initial request “/foo”

Immediate redirect to “/my.policy” Set MRHSession cookie

©2024 F515

15

General protocol flow Client Side Server Side

Initial request “/foo”

Immediate redirect to “/my.policy” Set MRHSession cookie

Request to “/my.policy” with cookie

©2024 F516

16

General protocol flow Client Side Server Side

Initial request “/foo”

Immediate redirect to “/my.policy” Set MRHSession cookie

Request to “/my.policy” with cookie

Redirect back to “/foo”

©2024 F517

17

General protocol flow Client Side Server Side

Initial request “/foo”

Immediate redirect to “/my.policy” Set MRHSession cookie

Request to “/my.policy” with cookie

Redirect back to “/foo”

Request “/foo” with cookie SSO

©2024 F518

18

General protocol flow Client Side Server Side

Initial request “/foo”

Immediate redirect to “/my.policy” Set MRHSession cookie

Request to “/my.policy” with cookie

Redirect back to “/foo”

Request “/foo” with cookie

All subsequent requests (with cookie) Bypasses access policy evaluation

SSO

SSO

©2024 F519

Smart Cards and APM

©2024 F520

A CAC or PIV is a collection of public and private keys stored on a Smart Card issued by a Public Key Infrastructure (PKI).

The certificates can be used to establish a mutual trust between the user and the server.

A client, such as a browser, can be used to provide this credential to a server or website.

When a smart card is inserted into a machine the public certs are copied to the system’s certificate store.

What is a Common Access Card (CAC)/Personal Identity Verification (PIV)?

©2024 F521

A CAC or PIV is a collection of public and private keys stored on a smart card issued by DOD Public Key Infrastructure (PKI).

The certificates can be used to establish a mutual trust between the user and the server.

A client, such as a browser, can be used to provide this credential to a server or website.

When a smart card is inserted into a machine the public certs are copied to the system's certificate store.

What is a Common Access Card (CAC)/Personal Identity Verification (PIV)?

CAC EXAMPLE

©2024 F522

Certificate bundle to authenticate the certificate from the CAC/PIV.

Online Certificate Status Protocol (OCSP) server, Certificate Revocation List (CRL), or CRL Distribution Point (CRLDP) for revocation checking of the certificate.

Active Directory, LDAP, or another directory service to query the identity of the authenticated user.

Configuration Requirements

©2024 F523

23

SSL protocol flow with APM ODCA, ignore in clientssl profile

Client Side Server Side

1. Client initiates SSL session

2. LTM presents server cert from clientssl profile

4. Client browser shows pop-up with available certs from user cert store, because ODCA causes an SSL renegotiation which requests a client cert. Available certs are controlled by the Advertised Certificate Authorities in the clientssl profile

5. Client chooses their cert, the software that talks to the smart card will prompt for PIN to decrypt the user’s private key on the card

6. The F5 will verify the client cert against the certificate bundle in the Trusted Certificate Authorities

7. Client is allowed access to the app

3. SSL session is established, client begins to be evaluated by APM VPE

©2024 F524

ODCA has been the preferred method of requesting the client certificate from a CAC/PIV for many years. It’s flexible.

Users can browse the website until they try to access restricted resources and perform “step up” authentication which would request or require the user certificate.

ODCA allows fallback authentication options like username/password.

Vulnerable to session hijacking if a Man in the Browser (MITB) is present.

MITB steals the cookie and sends it to the attacker

Stolen cookies could be used to resume sessions

BIG-IP APM On Demand Certificate Authentication (ODCA)

©2024 F525

25

SSL protocol flow with APM, require in clientssl profile

Client Side Server Side

1. Client initiates SSL session

2. LTM presents server cert from clientssl profile

3. LTM clientssl profile requests client cert

4. Client browser shows pop-up with available certs from user cert store. Available certs are controlled by the Advertised Certificate Authorities in the clientssl profile

5. Client chooses their cert, the software that talks to the smart card will prompt for PIN to decrypt the users private key on the card

6. The F5 will verify the client cert via the certificate bundle in the Trusted Certificate Authorities

©2024 F526

26

Continued… Client Side

Server Side

8. APM prompts user with a consent banner

9. UPN/EDIPI is verified from certificate.

10. Cert OID is verified from certificate.

11. OCSP request to check certificate revocation status.

12. LDAP/AD Query to verify user exists and account is enabled.

13. Client is allowed access to the app

7. Client begins to be evaluated by APM VPE

©2024 F527

This is the most secure option. It’s rigid.

This method will also work with clients/agents that are unable to handle redirects from APM. This is known as clientless mode.

If the user does not present a certificate the browser will fail to an SSL error page – no comfort pages.

BIG-IP APM with ClientSSL set to required

©2024 F528

Configuration Walkthrough and Recommended Practices

©2024 F529

The settings and recommended practices discussed have not been tested with every possible configuration and may negatively impact your environments.

Please test before making these changes in production.

Understand the settings and how they may affect your environment.

Disclaimer

©2024 F530

Maximum Session Timeout

Max Sessions Per User

Max In Progress Sessions Per Client IP

Restrict to Single Client IP

K000138221: Mitigate potential attacks using features included with BIG-IP APM

HTTP Only Cookies

”Persistent” Cookies

Samesite Cookies

Revocation Checks

…and more

©2024 F531

The Maximum Session Timeout setting is an important attribute for a BIG-IP APM access profile because it defines the maximum length of time a session can be active before it is automatically terminated. By limiting the duration of each session, you can mitigate the risk of session hijacking where an attacker could steal or use the session cookie to gain unauthorized access to confidential resources.

The Max Sessions Per User setting can be used to limit the number of times an individual user can create sessions into your application. It may not be unusual for a user to create multiple sessions into your application but this can be limited to reduce the possibility of session hijacking.

K000138221: Mitigate potential attacks using features included with BIG-IP APM

©2024 F532

The Max In Progress Sessions Per Client IP setting in a BIG-IP APM access profile is a security configuration that limits the number of simultaneous sessions that a client can initiate from a single IP address. This setting can be helpful to prevent either accidental or intentional session flooding on the BIG-IP, however if your clients are behind a proxy this setting may cause issues.

The Restrict to Single Client IP setting is an essential security measure within a BIG-IP APM access profile. When enabled, this setting ensures that a session can be accessed only from the same IP address from which it was initially created. This is a potent safeguard against attacks such as session hijacking or cookie theft, as even if an attacker manages to steal a session cookie, they cannot use it from a different IP address. This setting effectively ties the user session to a specific IP address, further enhancing the security of the BIG-IP APM access profiles.

K000138221: Mitigate potential attacks using features included with BIG-IP APM

©2024 F533

F5 recommends enabling the HTTP Only option. This measure is designed to mitigate the risk of client-side scripts gaining access to the BIG-IP APM session cookies, thus enhancing the security of your sessions.

The Persistent cookie option in APM can present a security risk and is disabled by default. This option is primarily used when the session needs to be resumed by another application, such as Office Suite for Sharepoint. The cookies are set to expire after 60 seconds. Persistent cookies can be accessed by other processes.

Samesite cookie protection was added as an option beginning in BIG-IP APM 16.0. You can enable this setting to add the samesite attribute to the APM session cookie. This attribute enforces samesite usage and prevents the cookie from being included with cross-site requests.

K000138221: Mitigate potential attacks using features included with BIG-IP APM – Cookie options

©2024 F534

K000138221: Mitigate potential attacks using features included with BIG-IP APM

Strict: Only include the cookie with requests originating from the same site as the cookie. Lax: Include the cookie with same-site requests and with top-level cross-site navigations that use a safe HTTP method.

©2024 F535

Revocation checks

The best revocation check option is Online Certificate Status Protocol (OCSP). OCSP can be configured within the BIG-IP APM to either use a configured responder or reference the responders within the Authority Information Access (AIA) extension of the certificate.

Certificate Revocation Lists (CRL) can be manually or automatically updated on the BIG-IP to verify revocation status of client certificates. The max file size for a CRL is now 192MB (15.x+).

Certificate Revocation List Distribution Points (CRLDP) is the final option for revocation status checking. This is the least desirable option due to the time it takes to pull a large CRL file. The CRLDP, like OCSP, can be statically defined or pulled from the AIA extension.

K000138221: Mitigate potential attacks using features included with BIG-IP APM

©2024 F536

UPN Checks – verify the cert contains a properly formatted User Principal Name (UPN) in the cert extensions

Cert OID Checks – verify appropriate user OIDs are present in the cert extensions - deny Non-Person Entity (NPE) certs

ClientSSL profile frequency always – enforce mTLS continuously

Limit the scope of advertised CAs and trusted CAs – bundle manager

Serial Number Check – verify serial number of cert matches initial APM session variables

…and more

©2024 F537

ClientSSL and Bundles

This bundle contains the full trust chain to validate the client certificate.

This bundle contains only the certificate authorities that sign the client certificate. This limits the advertised scope in the SSL negotiation within the browser.

Client Certificate is required and will fail negotiation if no certificate is present.

Always will force the browser to continuously send the certificate on session resumption.

©2024 F538

Policy Properties Default 15 minutes

Default 5 minutes

Default 128!

Default unlimited!

Default 7 days!

©2024 F539

Certificate Bundles

©2024 F540

Example Visual Policy Editor (VPE)

©2024 F541

Example Visual Policy Editor (VPE)

©2024 F542

Example Visual Policy Editor (VPE)

©2024 F543

Example Visual Policy Editor (VPE)

©2024 F544

Example Visual Policy Editor (VPE)

©2024 F545

Example Visual Policy Editor (VPE)

©2024 F546

More iRules!

©2024 F547

More iRules! https://community.f5.com/kb/technicalarticles/fingerprinting-tls-clients-with-ja4-on-f5-big-ip/326298

proc getCipherList { payload rlen outer inner clientip serverip } {

upvar cipher_cnt cipher_cnt

## Define GREASE values so these can be excluded from cipher list

set greaseList "0a0a 1a1a 2a2a 3a3a 4a4a 5a5a 6a6a 7a7a 8a8a 9a9a aaaa baba caca dada eaea fafa"

## Skip over first 43 bytes (contains tls_type hello_len tls_ver, which we don't need)

set field_offset 43

## Grab the session ID length value and increment field_offset.

binary scan ${payload} @${field_offset}c sessID_len

set field_offset [expr {${field_offset} + 1 + ${sessID_len}}]

## Grab ciphersuite list length (binary and hex values).

binary scan ${payload} @${field_offset}S cipherList_len

binary scan ${payload} @${field_offset}H4 cipherList_len_hex

set cipherList_len_hex_text ${cipherList_len_hex}

## increment field_offset and get the ciphersuite list.

set field_offset [expr {${field_offset} + 2}]

set cipherList_len_hex [expr {${cipherList_len} * 2}]

binary scan ${payload} @${field_offset}H${cipherList_len_hex} cipherlist

## Parse through cipherlist, add each non-GREASE cipher to cipherSuite list.

set cipher_cnt 0

set parsed_cl $cipherlist

set cipherSuite {}

set cl_offset 0

while {[scan $parsed_cl %4s%n cipherhex length] == 2} {

if { [lsearch -sorted -inline $greaseList $cipherhex] eq "" } {

lappend cipherSuite $cipherhex

incr cipher_cnt

} else {

#log local0. "CipherList: Found GREASE cipher '${cipherhex}'"

}

set parsed_cl [string range $parsed_cl $length end]

This iRule is 214 lines of code to generate a fingerprint for the browser/client

©2024 F548

©2024 F550

Appendix

©2024 F551

Decision pages – confirm_box.inc

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html><head><title>Department of Defense</title>

<link rel="stylesheet" type="text/css" HREF="/public/include/css/apm.css<? if ($GLOBALS["ap_version"]=="v2") { print("?v=v2"); } ?>">

<script language="JavaScript" src="/public/include/js/session_check.js?v=13"></script>

<script language="JavaScript" src="/public/include/js/agent_common.js"></script>

<script language="javascript"><!--//

if(self != top) { top.location = self.location; }

window.onerror=function(){ return function(){ return; } }

<? include_customized_page("logout", "session_expired.js"); ?>

function sessionTimedOut()

{

window.sessionTimeout.showSplashLayer("MessageDIV", SessionExpired_CustomizedScreenGet());

}

function OnLoad()

{

setFormAttributeByQueryParams("hidden_form", "action", "/confirm.php3");

try{

if ( "undefined" != typeof(window.external) && "unknown" != typeof(window.external)

&& "undefined" != typeof(window.external.WebLogonNotifyUser) && "unknown" != typeof(window.external.WebLogonNotifyUser) ){

window.external.WebLogonNotifyUser();

}

}catch(e){};

window.sessionTimeout = new APMSessionTimeout(sessionTimedOut);

}

©2024 F552

Decision pages – decision_box.inc

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html><head><title>Department of Defense</title>

<link rel="stylesheet" type="text/css" HREF="/public/include/css/apm.css<? if ($GLOBALS["ap_version"]=="v2") { print("?v=v2"); } ?>">

<script language="JavaScript" src="/public/include/js/session_check.js?v=13"></script>

<script language="JavaScript" src="/public/include/js/web_host.js"></script>

<script language="javascript"><!--//

if(self != top) { top.location = self.location; }

window.onerror=function(){ return function(){ return; } }

<? include_customized_page("logout", "session_expired.js"); ?>

function sessionTimedOut()

{

try{

if ( externalWebHost.hasWebLogonClearSession() ){

externalWebHost.webLogonClearSession();

}

}catch(e){};

window.sessionTimeout.showSplashLayer("MessageDIV", SessionExpired_CustomizedScreenGet());

}

function OnLoad()

{

try{

if ( externalWebHost.hasWebLogonNotifyUser() ){

externalWebHost.WebLogonNotifyUser();

}

}catch(e){};

©2024 F553

UPN and username variable assign

session.logon.last.upn

set x509e_fields [split [mcget {session.ssl.cert.x509extension}] "\n"];

# For each element in the list:

foreach field $x509e_fields {

# If the element contains UPN:

if { $field contains "othername:UPN" } {

## set start of UPN variable

set start [expr {[string first "othername:UPN<" $field] +14}]

# UPN format is <user@domain>

# Return the UPN, by finding the index of opening and closing brackets, then use string range to get everything between.

return [string range $field $start [expr { [string first ">" $field $start] - 1 } ] ]; } }

# Otherwise return UPN Not Found:

return "UPN-NOT-FOUND";

session.logon.last.username

set upn [mcget {session.logon.last.upn}]; if {[string first "@" $upn] >= 0} {

return [string range $upn 0 [expr { [string first "@" $upn] - 1 } ] ]; } else { return $upn; }

©2024 F554

UPN and username variable assign

session.logon.last.upn

set x509e_fields [split [mcget {session.ssl.cert.x509extension}] "\n"];

# For each element in the list:

foreach field $x509e_fields {

# If the element contains UPN:

if { $field contains "othername:UPN" } {

## set start of UPN variable

set start [expr {[string first "othername:UPN<" $field] +14}]

# UPN format is <user@domain>

# Return the UPN, by finding the index of opening and closing brackets, then use string range to get everything between.

return [string range $field $start [expr { [string first ">" $field $start] - 1 } ] ]; } }

# Otherwise return UPN Not Found:

return "UPN-NOT-FOUND";

session.logon.last.username

set upn [mcget {session.logon.last.upn}]; if {[string first "@" $upn] >= 0} {

return [string range $upn 0 [expr { [string first "@" $upn] - 1 } ] ]; } else { return $upn; }

©2024 F555

CERTOID Check

when ACCESS_POLICY_AGENT_EVENT {

if { [ACCESS::policy agent_id] eq "OIDCHECK" } {

## find and store CERT OID

if { [ACCESS::session data get session.ssl.cert.x509extension] contains "Policy: " } {

ACCESS::session data set session.custom.oid "[string trim [findstr [ACCESS::session data get session.ssl.cert.x509extension] "Policy: " 8 " "]]"

}

}

}

when ACCESS_ACL_ALLOWED {

#### OPTIONAL HEADER INSERTS

HTTP::header insert CERTOID [ACCESS::session data get session.custom.oid]

HTTP::header insert CERTSUBJECT [ACCESS::session data get session.ssl.cert.subject]

HTTP::header insert CERTSERIAL [ACCESS::session data get session.ssl.cert.serial]

HTTP::header insert USERNAME [ACCESS::session data get session.logon.last.username]

}

©2024 F556

Cert OID Check Branch Rules

User SW Cert expr { [mcget {session.custom.oid}] == "2.16.840.1.101.2.1.11.39" || [mcget {session.custom.oid}] == "2.16.840.1.101.2.1.11.40" || [mcget {session.custom.oid}] == "2.16.840.1.101.2.1.11.41" }

User HW Cert expr { [mcget {session.custom.oid}] == "2.16.840.1.101.2.1.11.42" || [mcget {session.custom.oid}] == "2.16.840.1.101.2.1.11.43" || [mcget {session.custom.oid}] == "2.16.840.1.101.2.1.11.44" }

NPE Cert expr { [mcget {session.custom.oid}] == "2.16.840.1.101.2.1.11.36" || [mcget {session.custom.oid}] == "2.16.840.1.101.2.1.11.37" || [mcget {session.custom.oid}] == "2.16.840.1.101.2.1.11.38" }

©2024 F557

LDAP Query Branch Rule expr {[mcget {session.ldap.last.queryresult}] == 1 && [mcget {session.ldap.last.attr.userAccountControl}] != 66050 && [mcget {session.ldap.last.attr.lockoutTime}] == 0 }

©2024 F558

Serial Number Binding

# APM_X509_SN_Binding

# Copyright 2024 F5

# Binds an APM session to a X509 serial number from an mTLS connection

# invalidates SSL session and removes APM session on mismatch

# requires "client-certificate required" to be present in the clientssl profile

# compatible with TLS 1.2/1.3

when ACCESS_ACL_ALLOWED priority 100 {

set tuple [IP::local_addr]:[TCP::local_port]->[IP::remote_addr]:[TCP::remote_port]

# ensure client certificate is present

if {[SSL::cert count] eq 0} {

ACCESS::log accesscontrol.warn "APM_X509_SN_Binding - No Client Certificate present $tuple "

ACCESS::respond 403 content {<html><h1>Access Denied</h1></html>}

ACCESS::session remove

SSL::session invalidate

return

}

set sn [X509::serial_number [SSL::cert 0]]

# does client-certificate serial match serial stored with APM session

if {[ACCESS::session data get "session.ssl.cert.serial"] eq $sn} {

ACCESS::log accesscontrol.info "APM_X509_SN_Binding - Client Certificate SN match: $sn"

return

}

ACCESS::log accesscontrol.warn "APM_X509_SN_Binding - Attempted session hijack from $tuple with mismatched Client Certificate SN: $sn"

ACCESS::respond 403 content {<html><h1>Access Denied</h1></html>}

ACCESS::session remove

SSL::session invalidate

}